home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / share / laptop-mode-tools / modules / wireless-power < prev   
Encoding:
Text File  |  2012-05-20  |  2.9 KB  |  92 lines

  1. #! /bin/sh
  2. # Laptop mode tools module, called from /usr/sbin/laptop_mode.
  3. # Configuration in /etc/laptop-mode/conf.d/wireless-power.conf.
  4. #
  5. # PURPOSE: power saving for generic wireless adapters that support
  6. #          the iwconfig power command.
  7. #
  8.  
  9. [ "$WIRELESS_POWER_SAVING_EXCLUDE_DRIVERS" ] || WIRELESS_POWER_SAVING_EXCLUDE_DRIVERS="iwl3945 iwl4965 iwlagn ipw3945 ipw2200 ipw2100"
  10.  
  11. #
  12. # Find all the wireless devices that do not use an excluded driver.
  13. # Place the interface names on the list WIFI_IFNAMES.
  14. #
  15. findWifiIfs () {
  16.     local SYSDEVICE EXCLUDED LINK_TARGET DRIVER IFNAME EXCLUDED_DRIVER;
  17.     
  18.     for SYSDEVICE in /sys/class/net/*; do
  19.         IFNAME=`basename $SYSDEVICE`
  20.  
  21.                 # Check if it is a wireless device
  22.         #
  23.         # Inverting return values, we get "0" for wireless device, 
  24.         # and "1" for non-wireless device.
  25.         ($IWCONFIG $IFNAME 2>&1 | grep -q "no wireless extensions.") && ret=1 || ret=0
  26.                 if [ "$ret" = "0" ]; then
  27.             # Yes, it is a wireless device.
  28.             if [ -h $SYSDEVICE/device/driver ]; then
  29.                 # Read the driver name
  30.                 LINK_TARGET=`readlink $SYSDEVICE/device/driver`
  31.                 DRIVER=${LINK_TARGET##*/}
  32.                 
  33.                 EXCLUDED=0
  34.                 for EXCLUDED_DRIVER in $WIRELESS_POWER_SAVING_EXCLUDE_DRIVERS ; do
  35.                     if [ "$EXCLUDED_DRIVER" = "$DRIVER" ] ; then
  36.                         log "VERBOSE" "Wireless interface $IFNAME excluded for wireless-power by driver name."
  37.                         EXCLUDED=1
  38.                     fi 
  39.                 done
  40.                 if [ $EXCLUDED = 0 ] ; then
  41.                     # add the interface name to the list
  42.                     WIFI_IFNAMES="$WIFI_IFNAMES $IFNAME"
  43.                 fi
  44.             fi
  45.  
  46.                 fi
  47.     done
  48. }
  49.  
  50. if [ x$CONTROL_WIRELESS_POWER_SAVING = x1 ] || [ x$ENABLE_AUTO_MODULES = x1 -a x$CONTROL_WIRELESS_POWER_SAVING = xauto ]; then
  51.     log "VERBOSE" "Setting power saving for generic wireless interfaces."
  52.  
  53.     # Provide defaults for config file settings
  54.     [ "$WIRELESS_AC_POWER_SAVING" ]   || WIRELESS_AC_POWER_SAVING=0
  55.     [ "$WIRELESS_BATT_POWER_SAVING" ] || WIRELESS_BATT_POWER_SAVING=1
  56.  
  57.     # Find executables
  58.     if [ -x /sbin/iwconfig ] ; then
  59.         IWCONFIG=/sbin/iwconfig
  60.     elif [ -x /usr/sbin/iwconfig ] ; then
  61.         IWCONFIG=/usr/sbin/iwconfig
  62.     else
  63.         log "VERBOSE" "iwconfig is not installed"
  64.     fi
  65.  
  66.     # Translate 1 => on, 0 => off
  67.     WIRELESS_AC_POWER_SAVING_ONOFF=off
  68.     WIRELESS_BATT_POWER_SAVING_ONOFF=off
  69.     [ "$WIRELESS_AC_POWER_SAVING" = 1 ] && WIRELESS_AC_POWER_SAVING_ONOFF=on
  70.     [ "$WIRELESS_BATT_POWER_SAVING" = 1 ] && WIRELESS_BATT_POWER_SAVING_ONOFF=on
  71.  
  72.     WIFI_IFNAMES=""
  73.     findWifiIfs
  74.     for IF in $WIFI_IFNAMES ; do
  75.         if [ $ON_AC -eq 1 ] ; then
  76.             log "VERBOSE" "On AC power: setting power saving mode for $IF to $WIRELESS_AC_POWER_SAVING_ONOFF."
  77.             if ( ! $IWCONFIG $IF power $WIRELESS_AC_POWER_SAVING_ONOFF ) ; then
  78.                 log "ERR" "Failed."
  79.             fi
  80.         else
  81.             log "VERBOSE" "On battery: setting power saving mode for $IF to $WIRELESS_BATT_POWER_SAVING_ONOFF."
  82.             if ( ! $IWCONFIG $IF power $WIRELESS_BATT_POWER_SAVING_ONOFF ) ; then
  83.                 log "ERR" "Failed."
  84.             fi
  85.         fi
  86.     done
  87. else
  88.     log "VERBOSE" "Generic wireless interface power saving module is disabled."
  89. fi
  90.  
  91.